# Contributor: Zach DeCook <zachdecook@librem.one>
# Maintainer: Zach DeCook <zachdecook@librem.one>
pkgname=hyprland
pkgver=0.39.1
pkgrel=0
_commit="fe7b748eb668136dd0558b7c8279bfcd7ab4d759"
_wlroots_commit="611a4f24cd2384378f6e500253983107c6656c64"
_wlroots_date=20240414
pkgdesc="Highly customizable dynamic tiling Wayland compositor that doesn't sacrifice on its looks."
url="https://hyprland.org"
arch="all"
license="BSD-3-Clause"
source="
	https://github.com/hyprwm/Hyprland/archive/v$pkgver/Hyprland-v$pkgver.tar.gz
	https://github.com/hyprwm/wlroots-hyprland/archive/$_wlroots_commit/wlroots-hyprland-$_wlroots_commit.tar.gz
	use-system-installed-udis86.patch
	"
builddir="$srcdir/Hyprland-$pkgver"
makedepends="
	cairo-dev
	cmake
	elogind-dev
	eudev-dev
	glslang-dev
	hwdata-dev
	hyprcursor-dev>=0.1.7
	hyprland-protocols
	hyprlang
	jq
	libcap-dev
	libdisplay-info-dev
	libdrm-dev
	libinput-dev
	libliftoff-dev
	libseat-dev
	libxcb-dev
	libxkbcommon-dev
	mesa-dev
	meson
	ninja
	pango-dev
	pixman-dev
	tomlplusplus-dev
	udis86-git-dev
	vulkan-loader-dev
	wayland-dev
	wayland-protocols
	xcb-util-image-dev
	xcb-util-renderutil-dev
	xcb-util-wm-dev
	xkeyboard-config-dev
	xwayland-dev
	"
subpackages="$pkgname-doc $pkgname-dev $pkgname-wallpapers::noarch"

prepare() {
	default_prepare
	# Use downloaded wlroots (instead of git submodule)
	rmdir subprojects/wlroots-hyprland
	mv "$srcdir/wlroots-hyprland-$_wlroots_commit" "$builddir"/subprojects/wlroots-hyprland
	# Change the soversion (appending current hyprland version)
	cd "$builddir"/subprojects/wlroots-hyprland
	# Make the version number valid
	sed -i "s/-dev/_git$_wlroots_date/" "$builddir"/subprojects/wlroots-hyprland/meson.build
	# Set some variables in version.h.in
	sed -i "s/@HASH@/$_commit/" "$builddir"/src/version.h.in
	sed -i "s/@BRANCH@/build-alpine/" "$builddir"/src/version.h.in
	message="with patches: $(printf %s "$source" | grep '.patch$' | tr '\n' ' ')"
	sed -i "s~@MESSAGE@~$message~" "$builddir"/src/version.h.in
	sed -i "s/@TAG@/v$pkgver/" "$builddir"/src/version.h.in
}

build() {
	abuild-meson . output
	meson compile ${JOBS:+-j ${JOBS}} -C output
}

check() {
	meson test --no-rebuild -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

wallpapers() {
	pkgdesc="Wallpapers for Hyprland"

	amove usr/share/hyprland/wall*.png
}

sha512sums="
173dc2baea68e301fad13b1634779f859263abdba7ab60233791c6c8c8ed2def24afdfb51d3db1820646b391530f1f6aeca82d8cf6de1ef178810c11fbdef37b  Hyprland-v0.39.1.tar.gz
157c94643bc630b1c97f05f620c2adb21f744cac16ed8c53ab377820ce8af2ec6b826197a41b6814a838b6e032b92a790f4214210831f8e91a6aff0346f54027  wlroots-hyprland-611a4f24cd2384378f6e500253983107c6656c64.tar.gz
d2f7b35552fa0a3e992b9050f7066d983b3b7c193a888018b2e0d6fa9e17fc3deff922fa3989d0bb79e8bd82df2bc16ff0c27a82759ad0ce2e72789506eb07db  use-system-installed-udis86.patch
"
